<template>
  <view>
    <uni-file-picker v-model="imageValue" fileMediatype="image" mode="grid" @select="select" @progress="progress"
      @success="success" @fail="fail" />
    <button @click="upload">上传</button>
    <image :src="img"></image>
  </view>
</template>
<script>
export default {
  data() {
    return {
      imageValue: [],
      filePaths: [],
      formData: {
        uploadedFiles: [] //已被上传的文件
      },
      img: ''
    }
  },
  methods: {
    select(e) {
      console.log(e)
      this.filePaths.push(e.tempFilePaths[0])
    },
    upload() {
      console.log(this.filePaths)
      for (const filePath of this.filePaths) {
        uni.uploadFile({
          url: '/image',
          filePath: filePath,
          name: 'file',
          success: (uploadFileRes) => {
            console.log(uploadFileRes.data);
            this.img = import.meta.env.VITE_API_URL + '/image/' + JSON.parse(uploadFileRes.data)[0]
            console.log(this.img)
          }
        });
      }
    }
  }
}
</script>